#ifndef __LUA_LOG_H__
#define __LUA_LOG_H__

#define STRING_BEGIN(L,idx) lua_getglobal(L,"tostring");lua_pushvalue(L,idx<0?idx - 1:idx);lua_pcall(L,1,1,0);
#define GETSTRING(L) lua_tostring(L,-1)
#define STRING_END(L) lua_pop(L,1)
#define LogOutput stderr
#define ViewState(L,...) do{\
	int size = lua_gettop(L)+1;\
	fprintf(LogOutput,__VA_ARGS__);\
	fprintf(LogOutput,":\n");\
	for(int i=1;i<size;i++){\
		STRING_BEGIN(L,i);\
		fprintf(LogOutput,"\t%d,%s\n",i,GETSTRING(L));\
		STRING_END(L);\
	}\
}while(false);

#endif